//package com.atguigu.tingshu.album.config;
//
//import com.atguigu.tingshu.album.mapper.TrackInfoMapper;
//import com.atguigu.tingshu.common.constant.RedisConstant;
//import com.atguigu.tingshu.model.album.TrackInfo;
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
//import jakarta.annotation.PostConstruct;
//import org.redisson.api.RBloomFilter;
//import org.redisson.api.RedissonClient;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//
//import java.util.List;
//
//@Component
//public class BloomFilterConfig {
//
//    @Autowired
//    private RedissonClient redissonClient;
//    @Autowired
//    private TrackInfoMapper trackInfoMapper;
//
//    @PostConstruct
//    public void initBloomFilter() {
//        RBloomFilter<Long> bloomFilter = redissonClient.getBloomFilter(RedisConstant.ALBUM_BLOOM_FILTER);
//        // 初始化布隆过滤器，预计插入的数量和误判率
//        bloomFilter.tryInit(500000L, 0.02);
//        // 加载数据库的有效 ID 到布隆过滤器中
////        List<Long> validTrackIds = loadTrackIdsFromDB();  // 从数据库加载 ID 列表
////        validTrackIds.forEach(bloomFilter::add);
//    }
//
//    private List<Long> loadTrackIdsFromDB() {
//        // 查询数据库中的所有有效 trackId
//        List<TrackInfo> selectList = trackInfoMapper.selectList(new LambdaQueryWrapper<TrackInfo>().eq(TrackInfo::getIsDeleted, 0));
//        return selectList.stream().map(TrackInfo::getId).toList();
//    }
//}
